
function Q = timingPremiumObjectFunc(pai,setupTP)

if pai<0 || pai > 1
    Q = 1D35;
    return
end

Css     = setupTP.Css;
CHI     = setupTP.params.CHI;
CHI0    = setupTP.params.CHI0;
PHI     = setupTP.params.PHI;
U0      = setupTP.params.U0;
U0d     = setupTP.params.U0d;
B       = setupTP.params.B;
MUZss   = setupTP.params.MUZss; 
PHIzero = setupTP.params.PHIzero; 
BETTA   = setupTP.params.BETTA;
ALFA    = setupTP.params.ALFA;

expValue = -setupTP.N0*(1-pai)^((1-CHI)*(1-CHI0)) - setupTP.Nc*(1-pai)^(1-CHI) ...
           - setupTP.Nd*(1-pai)^((1-CHI)*(1-CHI0)) - setupTP.Nl*(1-pai)^(CHI*(PHI-1));
scaling  = mean(expValue);

res = setupTP.vf + U0*(setupTP.z_cu*(1-pai))^((1-CHI)*(1-CHI0)) ...
    + setupTP.d_cu/(1-CHI)*((setupTP.c_cu-B/MUZss*setupTP.c_cu)/(Css*setupTP.z_cu)^CHI0)^(1-CHI)*(1-pai)^(1-CHI)  ...
    + U0d*setupTP.d_cu*(setupTP.z_cu*(1-pai))^((1-CHI)*(1-CHI0)) ...
    + setupTP.d_cu*(setupTP.n_cu*PHIzero)^PHI/(1-1/PHI)*setupTP.z_cu^((1-CHI)*(1-CHI0)*PHI)...
      *(setupTP.c_cu-B/MUZss*setupTP.c_cu)^(CHI*(PHI-1))*(1-pai)^(CHI*(PHI-1))...
      *(Css*setupTP.z_cu)^(CHI0*(PHI-1)*(1-CHI))/setupTP.w_cu^(PHI-1) ...
    - BETTA*scaling*(mean((expValue./scaling).^(1-ALFA)))^(1/(1-ALFA));
    
Q   = res^2;
disp(['pai = ', num2str(pai)]);

end